# Gunicorn配置文件 - SchedulerAI Simplified
import multiprocessing
import os

# 服务器配置
bind = "0.0.0.0:8000"
workers = min(multiprocessing.cpu_count() * 2 + 1, 8)  # 最多8个worker
worker_class = "uvicorn.workers.UvicornWorker"
worker_connections = 1000

# 性能配置
max_requests = 1000
max_requests_jitter = 100
timeout = 300  # 5分钟超时，适合复杂项目优化
graceful_timeout = 30
keepalive = 2
preload_app = True

# 日志配置
log_dir = os.environ.get("LOG_DIR", "./logs")
os.makedirs(log_dir, exist_ok=True)

accesslog = f"{log_dir}/access.log"
errorlog = f"{log_dir}/error.log"
loglevel = "info"
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s" %(D)s'

# 进程管理
pidfile = f"{log_dir}/gunicorn.pid"
daemon = False
user = None
group = None

# 安全配置
limit_request_line = 4096
limit_request_fields = 100
limit_request_field_size = 8190